// imageTmpl.cpp
//
// Image template class


#include "image/imageTmpl.h"
#include "image/imageFuncs.h"

namespace simple{
    //
    // Specialization: set
    //

    template<> void set (Image<Pel8>& s, const Pel8& value)
    {
      s.lockImage ();

      Image<Pel8>::row_iterator i;
      long w = s.width ();
      Pel8* p;
      for (i=s.row_begin(); i != s.row_end(); i++) {
          p = i->p;
          memset (p, value, w);
      }

      s.unlockImage ();
    }


    template<> void set (Image<Pel32s>& s, const Pel32s& value)
    {
        s.lockImage ();

        if (s.height() < 1)
            return;

        Image<Pel32s>::row_iterator i;
        long w = s.width ();
        Pel32s* p;

        // Initialize the first line
        i = s.row_begin();
        Pel32s* p0 = i->p;
        p = p0;
        for (int x=0; x<w; x++)
            *p++ = value;

        long bytes = w * sizeof (Pel32s);
        for (; i != s.row_end(); i++) {
            p = i->p;
            memcpy (p, p0, bytes);
        }

        s.unlockImage ();
    }


    template<> void set (Image<RGB>& s, const RGB& value)
    {
        s.lockImage ();

        if (s.height() < 1)
            return;

        Image<RGB>::row_iterator i;
        long w = s.width ();
        RGB* p;

        // Initialize the first line
        i = s.row_begin();
        RGB* p0 = i->p;
        p = p0;
        for (int x=0; x<w; x++)
            *p++ = value;

        long bytes = w * sizeof (RGB);
        for (; i != s.row_end(); i++) {
            p = i->p;
            memcpy (p, p0, bytes);
        }

        s.unlockImage ();
    }

}